Skip to content

Instantly share code, notes, and snippets.

@k0kubun

k0kubun/bench.rb Secret

Created March 6, 2018 13:55
Show Gist options
  • Save k0kubun/7a1145f8391fbc3c076052d6f40d9e8e to your computer and use it in GitHub Desktop.
Save k0kubun/7a1145f8391fbc3c076052d6f40d9e8e to your computer and use it in GitHub Desktop.
require 'benchmark_driver'
Benchmark.driver do |x|
x.prelude %{
def script
i = 0
while i < 1000_000
i += 1
end
i
end
}
x.report 'while', %{ script }
x.loop_count 2000
x.verbose
x.rbenv(
'2.0.0::2.0.0-p0',
'2.5.0',
'2.6.0-preview1',
'2.6.0-preview1+JIT::2.6.0-preview1,--jit',
'trunk::after',
'trunk+JIT::after,--jit',
)
end
2.0.0: ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux]
2.5.0: ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-linux]
2.6.0-preview1: ruby 2.6.0preview1 (2018-02-24 trunk 62554) [x86_64-linux]
2.6.0-preview1+JIT: ruby 2.6.0preview1 (2018-02-24 trunk 62554) +JIT [x86_64-linux]
trunk: ruby 2.6.0dev (2018-03-06 trunk 62678) [x86_64-linux]
trunk+JIT: ruby 2.6.0dev (2018-03-06 trunk 62678) +JIT [x86_64-linux]
Calculating -------------------------------------
2.0.0 2.5.0 2.6.0-preview1 2.6.0-preview1+JIT trunk trunk+JIT
while 78.377 80.890 86.794 246.379 86.156 493.848 i/s - 2.000k times in 25.517747s 24.724790s 23.043058s 8.117574s 23.213697s 4.049833s
Comparison:
while
trunk+JIT: 493.8 i/s
2.6.0-preview1+JIT: 246.4 i/s - 2.00x slower
2.6.0-preview1: 86.8 i/s - 5.69x slower
trunk: 86.2 i/s - 5.73x slower
2.5.0: 80.9 i/s - 6.11x slower
2.0.0: 78.4 i/s - 6.30x slower
@brauliobo
Copy link

Use onliner i += 1 while i < 1000_000

@ipstone
Copy link

ipstone commented Mar 9, 2018

How about some other more complicated codes testing? - Rails?

@victormartins
Copy link

I just tried this script and got pretty much the same speed for ruby 2.0.0, 2.3.0 and 2.5.0.
I was expecting a bit of a difference between 2.0.0 and 2.5.0. Am I doing something wrong here?

2.0.0: ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin17.4.0]
2.3.0: ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin16]
2.5.0: ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin17]
Calculating -------------------------------------
                          2.0.0       2.3.0       2.5.0
               while     58.754      59.356      59.242 i/s -      2.000k times in 34.040247s 33.695179s 33.759657s

Comparison:
                            while
               2.3.0:        59.4 i/s
               2.5.0:        59.2 i/s - 1.00x  slower
               2.0.0:        58.8 i/s - 1.01x  slower

https://github.com/victormartins/learning_examples/blob/ab7491402032c7c892e29e601f0e184a7f042e36/benchmarking/ruby_versions_benchmark.rb#L35-L37

@brodock
Copy link

brodock commented Apr 18, 2018

@victormartins, different OS, linux vs mac, can explain the difference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment